{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.bool矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a: \n",
      " [[2 8 6 6 5]\n",
      " [3 8 8 3 9]\n",
      " [6 6 7 2 2]\n",
      " [3 3 8 6 8]\n",
      " [6 1 7 6 8]]\n",
      "a < 5: \n",
      " [[ True False False False False]\n",
      " [ True False False  True False]\n",
      " [False False False  True  True]\n",
      " [ True  True False False False]\n",
      " [False  True False False False]]\n"
     ]
    }
   ],
   "source": [
    "a = np.random.randint(1, 10, size=(5, 5))\n",
    "print(\"a: \\n\", a)\n",
    "\n",
    "print(\"a < 5: \\n\", a < 5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.条件矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a: \n",
      " [[2 9 1 6 6]\n",
      " [3 6 6 1 8]\n",
      " [7 7 6 1 4]\n",
      " [4 5 2 5 3]\n",
      " [7 1 2 8 2]]\n",
      "\n",
      " bool a < 5: \n",
      " [[ True False  True False False]\n",
      " [ True False False  True False]\n",
      " [False False False  True  True]\n",
      " [ True False  True False  True]\n",
      " [False  True  True False  True]]\n",
      "\n",
      " 条件矩阵:打印小于5的矩阵元素: \n",
      " [2 1 3 1 1 4 4 2 3 1 2 2]\n"
     ]
    }
   ],
   "source": [
    "a = np.random.randint(1, 10, size=(5, 5))\n",
    "\n",
    "print(\"a: \\n\", a)\n",
    "print(\"\\n bool a < 5: \\n\", a < 5)\n",
    "print(\"\\n 条件矩阵:打印小于5的矩阵元素: \\n\", a[a<5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
